package com.niit.handlers;

import com.niit.entity.User;
import com.niit.mapper.UserMapper;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class UserQueryExecutor {

    private String url;
    private String user;
    private String password;


    public List<User> getUsersByHobby(String hobby) {
        List<User> users = new ArrayList<>();

        String sql = "SELECT * FROM users WHERE userId =? and userPwd =? and userHobbies LIKE ?";

        try (Connection connection = DriverManager.getConnection(url, user, password);

             PreparedStatement ps = connection.prepareStatement(sql)) {

            ps.setString(1, "Anna");
            ps.setString(2, "111111");
            ps.setString(3, "%" + hobby + "%");

            ResultSet rs = ps.executeQuery();

            while (rs.next()){
                System.out.println(rs.getString(1));
                System.out.println(rs.getString("UserPwd"));
                System.out.println(rs.getString(3));
            }


        } catch (SQLException e) {
            e.printStackTrace();
        }

        return users;
    }
}